export { }
// eslint-disable-next-line @typescript-eslint/no-var-requires
const zlib = require('zlib')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')
function open(input) {
  const ext = path.extname(input)
  switch (ext) {
  case '.gz':
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    return unZip(input)
  case '.rar':
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    return unRar(input)
  case '.7z':
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    return un7z(input)
  default:
    break
  }
}
function unZip(src) {
  const gunzip = zlib.createGunzip()
  const inputStream = fs.createReadStream(src)
  const outputStream = fs.createWriteStream(src.slice(0, -3))
  console.log('outputStream')

  inputStream.pipe(gunzip).pipe(outputStream)
}
function unRar(src) {
  console.log('Rar解压后的', src)
}
function un7z(src) {
  console.log('7z解压后的', src)
}
open('./source.txt.gz')

function zip(src) {
  const gzip = zlib.createGzip()//创建压缩流
  const inputStream = fs.createReadStream(src)
  const outputStream = fs.createWriteStream(src+'.gz')
  inputStream.pipe(gzip).pipe(outputStream)
}
zip('source.txt')
